
var num = parseInt(location.search.substring(1));
var yzm="";
//点击获取验证码
$('.getcode').click(function(){
    var phone=$('.phone').val();
    if(phone==""){
        layer.msg('请输入手机号码');
        return false;
    }else if(!(/^1[34578]\d{9}$/.test(phone))){
        layer.msg('手机号码格式有误，请重新填写');
        return false;
    }else{
        $.ajax({
            type: "POST",
            url: $host+'/api/open/common/sendCode',
            data: {
                phone:$('.phone').val(),
                type:2
            },
            async: true,
            dataType:'json',
            success: function(result){
                yzm=result.data.code;
                console.log(yzm)
                if(result.status===400004){
                    layer.msg('即将跳转绑定手机号');
                    setTimeout(()=>{window.location.href="bangdingsjh.html"},1000);
                }
            },
            error:function(){
                console.log('获取验证码错误')
            }

        });
        codeButton();
    }
})

 function codeButton(){
    var code = $(".getcode");
    code.attr("disabled","disabled");
    setTimeout(function(){
        code.css("color","#DBDBDB");
    },1000)
    var time = 60;
    var set=setInterval(function(){
        code.text("重新获取"+--time+'s');    
    //code.text(+--time+"秒后重新获取");
    }, 1000);
    setTimeout(function(){
    code.attr("disabled",false).text("重新获取验证码");
    clearInterval(set);
    }, 60000);
} 

//点击登录
$('.btn_dl').click(function(){
    var phone=$('.phone').val();
    var code=$('.code').val();
    if(phone==''){
        layer.msg('请输入手机号码');
        return false;
    }else if(!(/^1[34578]\d{9}$/.test(phone))){
        layer.msg('手机号码格式有误，请重新填写');
        return false;
    }else if(code==''){
        layer.msg('请输入验证码');
        return false;
    }else if(code!=yzm){
        layer.msg('验证码错误');
        return false;
    }else{
        $.ajax({
            type: "POST",
            url: $host+'/api/open/login',
            data: {
                phone:phone,
                code:code
            },
            async: true,
            dataType:'json',
            success: function(result){
                console.log(result);
                if(result.status===900000){
                    switch (num) {
                        case 1:
                            localStorage.setItem('tok', result.data.token);
                            window.location.href = "index.html?token="+result.data.token;
                            break;
                        case 2:
                            localStorage.setItem('tok', result.data.token);
                            window.location.href = "woyaohk.html?token="+result.data.token;
                            break;
                        case 3:
                            localStorage.setItem('tok', result.data.token);
                            window.location.href = "gerenzx.html?token="+result.data.token;
                            break;
                        default:
                            break;
                    }
                }
            },
            error:function(){
                console.log('接口错误')
            }
        })
    }
})

//点击返回
$('.dlymfh').click(function(){
    window.location.href="index.html";
})

